package shuzi.util;

import java.util.Comparator;

import shuzi.data.Database;
import shuzi.model.BrandPhone;
import android.util.Log;

public class SnComparator implements Comparator<BrandPhone> {

	private int type = 0;

	public SnComparator(int type) {
		this.type = type;
	}

	@Override
	public int compare(BrandPhone lhs, BrandPhone rhs) {
		int lhsPrice = 0;
		int rhsPrice = 0;
		if(lhs.getBlackPrice().equals("")){
			lhsPrice = 0;
		}else{
			lhsPrice = Integer.parseInt(lhs.getBlackPrice());
		}
		
		if(rhs.getBlackPrice().equals("")){
			rhsPrice = 0;
		}else{
			rhsPrice = Integer.parseInt(rhs.getBlackPrice());
		}
		
		if (type == 0) {
			if (lhsPrice > rhsPrice) {
				return -1;
			} else {
				return 1;
			}
		} else if (type == 1) {
			if (lhsPrice < rhsPrice) {
				return -1;
			} else {
				return 1;
			}
		} else if (type == 2) {
			int lhsDate = 0;
			int rhsDate = 0;
			if(lhs.getListingDate()!=null&&!lhs.getListingDate().equals("")){
				lhsDate = Integer.parseInt(lhs.getListingDate().replaceAll("-", ""));
			}
			if(rhs.getListingDate()!=null&&!rhs.getListingDate().equals("")){
				rhsDate = Integer.parseInt(rhs.getListingDate().replaceAll("-", ""));
			}
			Log.d(Database.TAG, lhsDate+"--------------"+rhsDate);
			if (lhsDate > rhsDate) {
				return -1;
			} else {
				return 1;
			}
		}

		return 1;
	}

}
